package common.quickvalid.validators;

import java.util.Map;

/**
 * 必须和某个input field相等,用于密码两次输入验证 
 * equals-$otherInputId 
 * 示例: equals-password
 * @author beansoft
 *
 */
public class equals extends BaseValidator {

	public String doValidation(String fieldName, String fieldDescription,
	        Map<String, Object> params, String... args) {
		super.setParams(params);		
		String value = getValue(fieldName);
		String value2 = getValue(args[0]);
		String anotherFieldDescription = null;
		
		// 另一元素描述下标为1
		if(args.length > 1) {
			anotherFieldDescription = args[1];
		}
		
		// 非空时进行验证
		if(value != null && value.length() > 0 && value2 != null &&value2.length() > 0 ) {
			if(!value.equals(value2)) {
				if(anotherFieldDescription != null) {
					return fieldDescription + "和" + anotherFieldDescription + "的输入不一致";
				} else {
					return fieldDescription + "和前面的输入不一致";
				}
			}
		}
		return null;
	}

}